// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// p [author] rhyme_lph
// D [email]  rhymelph@gmail.com
// m [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/transaction_entity.dart';
import 'package:finance_app/src/mixin/refresh_mixin.dart';
import 'package:finance_app/src/mixin/time_sort_mixin.dart';
import 'package:finance_app/src/mixin/transaction_data_mixin.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';
import 'package:finance_app/src/utils/permission_utils.dart';

class DashboardTransactionsProvider
    extends BaseProvider<List<TransactionEntity>>
    with
        TimeSortMixin,
        TransactionDataMixin,
        RefreshMixin<List<TransactionEntity>, List<TransactionEntity>> {
  @override
  Future get dataFuture => null;

  @override
  void initState() {
    super.initState();
  }

  @override
  Future<void> onRefresh() async {
    Config.dashboardProvider.onRefreshDashboard(refreshTransaction: false);
    return super.onRefresh();
  }

  void onFilter() {}

  void onNavViewAll() async {
    await Routes.navigateTo(RouterGenProviders.allTransactionsPage, params: {
      'type': 7,
    });
    onRefresh();
  }

  @override
  void unFocus() {}

  @override
  List<String> get types => [
        if (Config.hasPermission(PermissionUtils.quotation)) 'quotation',
        if (Config.hasPermission(PermissionUtils.invoice)) 'invoice',
        if (Config.hasPermission(PermissionUtils.cashBank)) 'cash_in',
        if (Config.hasPermission(PermissionUtils.purchaseOrder))
          'purchase_order',
        if (Config.hasPermission(PermissionUtils.bill)) 'bill',
        if (Config.hasPermission(PermissionUtils.expense)) 'expense',
        if (Config.hasPermission(PermissionUtils.cashBank)) 'cash_out',
        if (Config.hasPermission(PermissionUtils.creditDebitNote))
          'credit_note',
        if (Config.hasPermission(PermissionUtils.creditDebitNote)) 'debit_note',
      ];

  @override
  List<TransactionEntity> get dataList => transactionList;
}
